//
//  CareTakerAccount.m
//  ALittleReminder
//
//  Created by Kevin Basanti on 11-11-20.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "CareTakerAccount.h"

@implementation CareTakerAccount


-(IBAction)goAway:(id)sender{
    [sender resignFirstResponder];
    
}
-(IBAction)tapBackground:(id)sender{
    [name resignFirstResponder];
    [password resignFirstResponder];
    [city resignFirstResponder];
    [phone resignFirstResponder];
    [hospital resignFirstResponder];
    [repassword resignFirstResponder];
}


-(IBAction)onClickCreate:(id)sender{
    if([password.text isEqualToString:repassword.text]){
        
        NSString *nameText = name.text;
        NSString *hospitalText = hospital.text;
        NSString *cityText = city.text;
        NSString *phoneText = phone.text;
        NSString *passwordText = password.text;
        
         
        
        if([ phoneText length] == 10){
            
        
        
            NSString *infoText=[nameText stringByAppendingFormat:@"-%@-%@-%@-%@",hospitalText,cityText,phoneText,passwordText];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *docDir = [paths objectAtIndex: 0];
            NSString *docFile = [docDir stringByAppendingPathComponent: @"caretakerInfo.txt"];
        
        //your variable "deck"
        
            
            NSError *error;
            if ([infoText writeToFile:docFile atomically:YES encoding:NSStringEncodingConversionAllowLossy error:&  error]
                ) {
                NSLog(@"saved");
            }else{
                NSLog(@"not saved: %@",error);
            }
        
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Account Created" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        
            
        }
        else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Phone Number" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
        
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Password Does Not Match" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
    
        
}

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons
    if (buttonIndex == 0)
    {
        [self dismissModalViewControllerAnimated:YES];
        
        
    }
}

-(IBAction)onClickClose:(id)sender{
    
    
    [self dismissModalViewControllerAnimated:YES];
    
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320, 1000)];
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
